mui.ready(function() {
	document.getElementById("login").addEventListener("click", function() {
		if (document.getElementById("c1").checked == false) {
			mui.toast("请勾选用户协议");
			return
		}

		if (document.getElementById("userName").value == "" || document.getElementById("password").value == "") {
			mui.toast("用户名/密码不能为空");
			return
		}

		var userName = document.getElementById("userName").value;
		var password = document.getElementById("password").value;

		mui.ajax('/api/v1/login', {
			data: {
				paramStr: "{'userName':'" + userName + "','deviceType':'h5','password':'" + password + "'}"
			},
			dataType: 'json',
			type: 'post',
			timeout: 10000,

			success: function(data) {
				if (data.code == 102) {
					mui.toast("用户或密码错误");
					return
				}

				if (data.code == 200) {
					mui.toast(data.message)
					var obj = eval('(' + data.data + ')')
					console.log(data.data);
					sessionStorage.id = obj.userInfo.id;
					sessionStorage.userName = obj.userInfo.userName;
					sessionStorage.mobile = obj.userInfo.mobile;
					sessionStorage.email = obj.userInfo.email;
					sessionStorage.pname = obj.userInfo.pname;
					sessionStorage.sex = obj.userInfo.sex;
					sessionStorage.partnerLevel = obj.userInfo.partnerLevel;
					sessionStorage.level = obj.userInfo.level;
					sessionStorage.token = obj.token;
					sessionStorage.isVerify= obj.userInfo.isVerify;
					sessionStorage.isMerchant=obj.userInfo.isMerchant;
					sessionStorage.money = obj.accountInfo.money;
					sessionStorage.cloudMoney = obj.accountInfo.cloudMoney;
					sessionStorage.cashbackMoney = obj.accountInfo.cashbackMoney;
					window.location.href = "homepage.html";
					
				}
			},
			error: function(xhr, type, errorThrown) {
				//异常处理；
				mui.toast("未知错误") 
			}
		});
	});
	document.querySelector(".index").addEventListener('tap', function() {
		mui.openWindow({
			url: '../index.html',
		});
	});
})